package com.ziguang.redwood.admin.service;

import java.util.List;

import com.jfinal.log.Log4jLog;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

public class NewsService {
	
	private static final Log4jLog log = Log4jLog.getLog(NewsService.class);
	
	public static final NewsService me = new NewsService();
	
	/**
	 * 获取新闻动态数据
	 */
	public List<Record> index(){
		List<Record> data=Db.find("select * from rw_news order by update_time");
		return data;
	}
	
	/**
	 * 获取当前数据
	 */
	public Record QueryEdit(String id){
		Record data = Db.findFirst("select * from rw_news where id = ?",id);
		return data;
	}
	
	/**
	 * 保存编辑数据
	 */
	public void save(String id,String title,String content){
		if(id != ""){
			Db.update("update rw_news set title = ?,content = ?,create_time = NOW(),update_time = NOW() where id = ?",
					title,content,id);
		}else{
			Db.update("insert into rw_news (title,content,reading,create_time,update_time) values (?,?,0,NOW(),NOW())",
					title,content);
		}
	}
	
	/**
	 * 删除当前数据
	 */
	public void delete(String id){
		Db.deleteById("rw_news",id);
	}
	
}
